package com.cmdi.controller;

import com.cmdi.annotation.SysLog;
import com.cmdi.domain.StuStudent;
import com.cmdi.model.R;
import com.cmdi.model.WebLog;
import com.cmdi.service.StuStudentService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description: 测试接口
 * @Author: gaozb
 */
@RestController
@Api(tags = "测试接口")
public class TestController {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private StuStudentService stuStudentService;

    @RequestMapping(value = "/a", method = RequestMethod.GET)
    @ApiOperation(value = "测试Swagger", authorizations = {@Authorization("123")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "m", dataType = "String"),
            @ApiImplicitParam(name = "n", dataType = "String")
    })
    public R<String> a(String m, String n) {
        System.out.println(m + n);
        return R.ok(m + n);
    }

    @RequestMapping(value = "/b", method = RequestMethod.GET)
    @ApiOperation(value = "测试Jaskson")
    @SysLog("ceshi123")
    public R<Date> b() {
        return R.ok(new Date());
    }

    @RequestMapping(value = "/c", method = RequestMethod.GET)
    @ApiOperation(value = "测试Redis")
    public R<String> c() {
        WebLog webLog = new WebLog();
        webLog.setBasePath("123");
        redisTemplate.opsForValue().set("key", webLog);
        return R.ok("good");
    }

    @RequestMapping(value = "/d", method = RequestMethod.GET)
    @ApiOperation(value = "测试权限不足")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "m", dataType = "String"),
            @ApiImplicitParam(name = "n", dataType = "String")
    })
    @SysLog("测试权限不足")
    @PreAuthorize("hasAuthority('p888')")
    public R<String> d() {
        return R.ok("ok");
    }

    @RequestMapping(value = "/e", method = RequestMethod.GET)
    @ApiOperation(value = "测试mybatisplus")
    @SysLog("mybatisplus")
    public R<StuStudent> e() {
        StuStudent student = stuStudentService.getById(1);
        return R.ok(student);
    }
}